package cn.saltybe.analysis.controller.api.statistic;

import cn.saltybe.analysis.entity.result.UniqueVisitor;
import cn.saltybe.analysis.service.UniqueVisitorServiceImpl;
import cn.saltybe.analysis.util.ApiResponse;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/statistic/user-view")
public class UserViewAPI {
    private UniqueVisitorServiceImpl uniqueVisitorService;

    @Autowired
    public void setUniqueVisitorService(UniqueVisitorServiceImpl uniqueVisitorService) {
        this.uniqueVisitorService = uniqueVisitorService;
    }

    @ResponseBody
    @GetMapping(value = "list")
    public String list() throws Exception {
        List<UniqueVisitor> list;
        list = uniqueVisitorService.all();
        JsonArray result = new Gson().toJsonTree(list).getAsJsonArray();
        return ApiResponse.buildSuccessResponse(result).toString();
    }
}
